<!--
 * @Description: 数据权限界面
-->
<template>
  <div class="datamain">
    <div class="title">数据权限表</div>
    <div class="table-box">
      <el-table
        ref="multipleTableone"
        v-loading="loading"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="82%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" :selectable="(row) => { return !row.selectable }" />
        <el-table-column type="index" label="序号" width="100" />
        <el-table-column prop="dataPermissionName" label="权限名称" />
        <el-table-column prop="paramName" label="字段名称" />
        <el-table-column prop="scope" label="范围" />
        <el-table-column prop="sign" label="符号" />
        <el-table-column prop="value" label="值" />
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </div>
  </div>
</template>
<script>
import userManage from "@/api/system-settings/user-manage";
import Pagination from "@/components/Pagination";
export default {
  components: {
    Pagination
  },
  props: {
    userid: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      // 表格数据
      tableData: [],
      // table
      loading: true,
      // 当前页
      currentPage: 1,
      // 每页的数据条数
      pageSize: 10,
      // 总条数
      totalSize: 0,
      // 选中的id列表
      permisslist: []
    }
  },
  mounted() {
    this.getdatamet()
  },
  methods: {
    getdatamet() {
      userManage.gettabledata().then(res => {
        let list = res.data.dataPermissionPageList
        this.totalSize = list.totalElements
        this.tableData = list.content
        this.loading = false
      });
      this.getdatauth()
      console.log("获取数据")
    },
    // 获取用户所拥有的数据权限
    getdatauth() {
      userManage.getdatauth({ id: this.userid }).then(
        res => {
          console.log(res.data)
          let list = res.data.scopeDataControl
          let that = this
          let selectindex = []
          if (list) {
            list.forEach(
              (item, index) => {
                that.tableData.forEach(
                  (itemtwo, indextwo) => {
                    if (itemtwo.dataPermissionId === item.dataPermissionId) {
                      selectindex.push(indextwo)
                    }
                  }
                )
              }
            )
          }

          this.$nextTick(() => {
            if (selectindex) {
              console.log(selectindex)
              selectindex.forEach(row => {
                that.$refs.multipleTableone.toggleRowSelection(this.tableData[row]);
              });
            } else {
              that.$refs.multipleTableone.clearSelection();
            }
          })
          console.log(res)
        }
      )
    },
    setpermission() {
      userManage.adddatauth({ 'permisslist': this.permisslist })
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getdatamet();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getdatamet();
    },
    handleSelectionChange(list) {
      // this.permisslist = []
      // list.forEach(
      //   (item, index) => {
      //     this.permisslist.index = item.dataPermissionId
      //   }
      // )

      // console.log(this.permisslist)
      // console.log(list)
    }
  }
}
</script>
<style lang="scss" scoped>
.title{
  font-size: 20px;
}
.datamain{
  width: 100%;
  .table-box {
    height: 90%;
  }
  // background-color: aqua;
}
</style>
